package com.tanhua.server.controller;

import com.tanhua.server.pojo.User;
import com.tanhua.server.utils.UserThreadLocal;
import com.tanhua.server.vo.HuanXinUser;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/huanxin")



public class HuanXinController {

    //将当前登录用户注册到环信的用户名和密码传递给前端
    @GetMapping("/user")
    public ResponseEntity<HuanXinUser> queryUser() {

        User user = UserThreadLocal.get();

        HuanXinUser huanXinUser = new HuanXinUser();
        //给前端的用户名和密码要和注册到环信中的一样,否则不能用
        huanXinUser.setUsername(user.getId().toString());
        huanXinUser.setPassword(DigestUtils.md5Hex(user.getId() + "_itcast_tanhua"));

        return ResponseEntity.ok(huanXinUser);
    }

}
